package com.cn.dream_order_server.async;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Async
public class OrderOrderAopAsync {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void orderOrderAopupdateUserSitePhoneAsync(String userId,Integer pageNo,Integer PageSize){
        String s = stringRedisTemplate.opsForValue().get("orderOrder-" + userId + "-all");
        if(s!=null&&!"".equals(s)){
            s=s+",orderOrder-"+ userId + "-"+ pageNo+"-"+PageSize;
        }else {
            s="orderOrder-"+ userId + "-"+ pageNo+"-"+PageSize;
        }
        stringRedisTemplate.opsForValue().set("orderOrder-" + userId + "-all",s,30,TimeUnit.MINUTES);
    }


   public void  orderOrderAopupdateUserSitePhone1Async(String userId,String ordertypeId,Integer pageNo,Integer PageSize,String objToString){
        switch (ordertypeId){
            case "1":
                stringRedisTemplate.opsForValue().set("orderOrderPayment-" + userId + "-" + pageNo+"-"+PageSize,objToString,30,TimeUnit.MINUTES);
                String s = stringRedisTemplate.opsForValue().get("orderOrderPayment-" + userId + "-all");
                if (s!=null&&!"".equals(s)){
                    s=s+",orderOrderPayment-" + userId + "-" + pageNo+"-"+PageSize;
                }else {
                    s="orderOrderPayment-" + userId + "-" + pageNo+"-"+PageSize;
                }
                stringRedisTemplate.opsForValue().set("orderOrderPayment-" + userId + "-all",s,30,TimeUnit.MINUTES);
                break;
            case "2":
                stringRedisTemplate.opsForValue().set("orderOrderWaitForReceiving-" + userId + "-" + pageNo+"-"+PageSize,objToString,30,TimeUnit.MINUTES);
                String s1 = stringRedisTemplate.opsForValue().get("orderOrderWaitForReceiving-" + userId + "-all");
                if (s1!=null&&!"".equals(s1)){
                    s1=s1+",orderOrderWaitForReceiving-" + userId + "-" + pageNo+"-"+PageSize;
                }else {
                    s1="orderOrderWaitForReceiving-" + userId + "-" + pageNo+"-"+PageSize;
                }
                stringRedisTemplate.opsForValue().set("orderOrderWaitForReceiving-" + userId + "-all",s1,30,TimeUnit.MINUTES);
                break;
            case "3":
                stringRedisTemplate.opsForValue().set("orderOrderAccomplish-" + userId + "-" + pageNo+"-"+PageSize,objToString,30,TimeUnit.MINUTES);
                String s2 = stringRedisTemplate.opsForValue().get("orderOrderAccomplish-" + userId + "-all");
                if (s2!=null&&!"".equals(s2)){
                    s2=s2+",orderOrderAccomplish-" + userId + "-" +pageNo+"-"+PageSize;
                }else {
                    s2="orderOrderAccomplish-" + userId + "-" + pageNo+"-"+PageSize;
                }
                stringRedisTemplate.opsForValue().set("orderOrderAccomplish-" + userId + "-all",s2,30,TimeUnit.MINUTES);
                break;
            case "4":
                stringRedisTemplate.opsForValue().set("orderOrderCancel-" + userId + "-" + pageNo+"-"+PageSize,objToString,30,TimeUnit.MINUTES);
                String s3 = stringRedisTemplate.opsForValue().get("orderOrderCancel-" + pageNo + "-all");
                if (s3!=null&&!"".equals(s3)){
                    s3=s3+",orderOrderCancel-" + userId + "-" + pageNo+"-"+PageSize;
                }else {
                    s3="orderOrderCancel-" + userId + "-" + pageNo+"-"+PageSize;
                }
                stringRedisTemplate.opsForValue().set("orderOrderCancel-" + userId + "-all",s3,30,TimeUnit.MINUTES);
                break;

        }
    }

}
